package com.tojabo.stack;

public class BracketChecker {

	private String input;
	private final static String Stop="stop";
	
	public BracketChecker(String in){
		input = in;
	}
	
	public void check(){
		int stackSize = input.length();
		StackX theStack = new StackX(stackSize);
		
		for(int j=0;j<input.length();j++){
			char ch = input.charAt(j);			
			switch(ch){
			case '{':
			case '[':
			case '(':
				theStack.push(ch);
				break;
			case '}':
			case ']':
			case ')':
				if(!theStack.isEmpty()){
					char chx = theStack.pop();
					if((ch=='}'&& chx=='{')||
						(ch==']'&& chx=='[')||
						(ch==')'&& chx=='(')){
						System.out.println("Error:"+ch+" at "+j);
					}
				}else{
					System.out.println();
				}
				break;
			default:
				break;	
			}//end switch
		}// end for
		
		if(!theStack.isEmpty()){
			System.out.println("Error: missing right delimiter");
		}
	} // end check()
	
}
